package com.avicsafety.ezsystem.mvp;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;

import com.avicsafety.ezsystem.mvp.presenter.BasePresenter;
import com.avicsafety.ezsystem.mvp.view.BaseView;

import butterknife.ButterKnife;

/**
 * 所有Acitivity鸡肋 实现了 对应的View方法和注入等
 */
public abstract class BaseActivity<T extends BasePresenter> extends AppCompatActivity implements BaseView {

    protected Context oThis;
    protected T presenter;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        init(0, null);
        initData();
        initEvent();
    }

    protected void init(Integer LayoutId, Class<T> clazz) {
        setContentView(LayoutId);
        oThis = this;
        ButterKnife.bind(this);
        try {
            presenter = clazz.newInstance();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        }
        presenter.attachView(this);
    }

    protected void initData() {

    }

    protected void initEvent() {

    }

    @Override
    public void showLoading() {
        Log.v("BaseActivity", "showLoading");
    }

    @Override
    public void closeLoading() {
        Log.v("BaseActivity", "closeLoading");
    }

    @Override
    public void showToast(String msg) {
        Log.v("BaseActivity", "showToast");

    }


    @Override
    protected void onDestroy() {
        super.onDestroy();
        presenter.detachView();
    }

}
